home *** CD-ROM | disk | FTP | other *** search
- Path: god.bel.alcatel.be!nlev00!barnhoorn
- From: barnhoorn@nlev00 ()
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: Messages vs. Semaphores for external clocking
- Date: 10 Apr 1996 10:34:02 GMT
- Organization: Alcatel Bell
- Distribution: world
- Message-ID: <4kg2qq$58l@btmpjg.god.bel.alcatel.be>
- References: <4ju349$r1e@sparky.navsea.navy.mil> <4jvrqs$hk0@btmpjg.god.bel.alcatel.be> <heinz.17rm@hwg.muc.de> <4kfmes$lle@btmpjg.god.bel.alcatel.be> <4kfuhb$ahh@serpens.rhein.de>
- Reply-To: barnhoorn@nlev00 ()
- NNTP-Posting-Host: 138.203.178.61
- X-Newsreader: mxrn 6.18-10
-
-
- In article <4kfuhb$ahh@serpens.rhein.de>, mlelstv@serpens.rhein.de (Michael van Elst) writes:
- >barnhoorn@nlev00 () writes:
- >
- >>.not so obviously. When you have two tasks, and one of them is
- >>collecting data from some source, and the other one needs this data
- >>with regular intervals, I don't see a more easier way to do this
- >>then by using global data and disable/enable multitasking.
- >
- >The trick is to disable multitasking only when necessary and only
- >for the tasks that are involved.
- >
- >>It is
- >>a very multitasking-friendly solution,
- >
- >No. You stop all other tasks (and with Disable() you even stop
- >interrupts which is nonsense).
-
- Agree (I meant Forbid()/Permit()). But 'you stop all other tasks'
- is wrong. In my Amiga only ONE task is running at the same time.
- When task 1 wants the data, the only thing it has to do is disable
- multitasking, (which does NOT stop all other tasks because they are
- already stopped), collect the data, and enable the multitasking again.
- We are talking (well, at least I am) here about very SIMPLE code
- like this:
-
-
- int global_data;
- int running;
-
- void Task1 (void)
- {
- int local_data;
-
- while (running) {
-
- Forbid();
- local_data=global_data;
- Permit();
-
- HandleDataFromOtherTask(local_data);
-
- WaitRegularInterval();
- }
- }
-
- void Task2(void)
- {
- int local_data;
-
- while (running) {
-
- CollectDataForMainTask(&local_data);
-
- Forbid();
- global_data=local_data;
- Permit();
-
- WaitRegularInterval();
- }
- }
-
- void main(void)
- {
- running=1;
-
- /* start the two processes */
-
- /* do whatever you like, you may even Wait() for user-interrupt */
-
- running=0;
-
- /* wait for the two processes to finish */
- }
-
-
- I really only wanted to state that in my opinion, forbid() and permit()
- is the most easiest, shortest and probably also fastest way to transfer
- the data from task2 to task1.
-
- --
- ---------------------------------------------------------------------------
- Jaco Barnhoorn barnie@xs4all.nl
- Software Test Engineer barnhoorn%nlev00@btmv56.se.bel.alcatel.be
- Alcatel Telecom Systems
- Rijswijk, The Netherlands
- ---------------------------------------------------------------------------
-